'''
下拉框 select option
操作步骤：
1）先获取select标签定位，然后将它强转为select对象 Select()
2)select对象中封装了下拉框中所有的选项，通过select对象.options获取
3) option.text获取下拉选项的文本
4）选中动作 通过文本选中select_by_visible_text，通过下拉序列下标选中select_by_index(1)，通过下拉框的value属性选中select_by_value
'''
import time


from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

driver = webdriver.Edge()
driver.get("http://127.0.0.1/ranzhi/www/")
time.sleep(1)

# 用户名密码
driver.find_element("xpath",'//*[@id="account"]').send_keys("admin")
driver.find_element("xpath",'//*[@id="password"]').send_keys("123456")
# 点击登录
driver.find_element("xpath",'//*[@id="submit"]').click()
time.sleep(1)

# 点击后台管理
driver.find_element("xpath",'//*[@id="s-menu-superadmin"]/button/i').click()

# 切换到iframe
# 定位到iframe
iframe = driver.find_element("id","iframe-superadmin")
driver.switch_to.frame(iframe)

# 点击添加成员
driver.find_element("class name","shortcut.user").click()

# 角色下拉框
role = driver.find_element("id","role")
# 强转为select对象
s = Select(role)
# 获取所有的下拉选项的对象
ls = s.options
listtext = []
for i in ls:
    listtext.append(i.text)

# 选中
# s.select_by_index(1)
# s.select_by_value("pm")
s.select_by_visible_text(listtext[3])

time.sleep(10)
# 切换到上一层
driver.switch_to.default_content()
# driver.switch_to.parent_frame()

# 点击签退
driver.find_element("class name","sign.signout").click()

time.sleep(20)
